package com.nwl.crm.rest;

import com.nwl.crm.dto.EmployeeDto;
import com.nwl.crm.service.EmployeeService;
import com.nwl.crm.util.PageUtil;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;

@RestController
@RequestMapping("employeeRest")
public class EmployeeRest extends AbstractRest<EmployeeDto>{

    //记录系统的日志
    Logger logger = LoggerFactory.getLogger(EmployeeRest.class);

    @Autowired
    private EmployeeService service;

    @Override
    public EmployeeDto getAll(EmployeeDto dto) {
        return null;
    }

    @Override
    @RequestMapping("layuiList")
    public PageUtil layuiList(EmployeeDto dto){
        try{
            PageUtil pageUtil = new PageUtil();
            dto.setPageUtil(pageUtil);
            service.layuiList(dto);

            dto.getPageUtil().setCode(0);
            dto.getPageUtil().setMsg("操作成功");
        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());
            dto.getPageUtil().setCode(-1);
            dto.getPageUtil().setMsg("系统异常");
        }
        return dto.getPageUtil();
    }

    @Override
    @RequestMapping("saveOrUpdate")
    public EmployeeDto saveOrUpdate(EmployeeDto dto) {
        try{
            service.saveOrUpdate(dto);

        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());

        }
        return dto;
    }

    @Override
    @RequestMapping("delete")

    public EmployeeDto delete(EmployeeDto dto) {
        try{
            service.delete(dto);

        }catch (Exception e){
            e.printStackTrace();
            logger.info(e.getMessage());

        }
        return dto;
    }
    }

